package com.hk.controller;

import com.hk.entity.LargeScreen;
import com.hk.entity.Result;
import com.hk.entity.gradeDesc;
import com.hk.service.LargeScreenService;
import com.hk.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 学生大屏控制器
 */
@Slf4j
@RestController
public class LargeScreenController {
    @Autowired
    private LargeScreenService largeScreenService;

    /**
     * 滚动大屏的接口
     * major 专业
     * courseName 课程名
     * stuName 学生姓名
     * grade 课程成绩
     * credit 学分
     * @return
     */
    @GetMapping("/gradeInfos")
    public Result gradeInfo(){
        List<LargeScreen> largeScreenList = largeScreenService.getGradeInfo();
        return Result.success(largeScreenList);
    }

    @GetMapping("/GradeDesc")
    public Result gradeDesc(@RequestHeader("token") String authorization){
        // 从token头中提取JWT令牌
        String token = authorization;

        // 解析JWT令牌并提取管理员ID
        Map<String, Object> claims = JwtUtils.parseJWT(token);
        String stuId = (String) claims.get("stuId");
        List<gradeDesc> gradeDescList = largeScreenService.getGradeDesc(stuId);
        return Result.success(gradeDescList);
    }
}
